// pages/mine/mine.js
const config = require('../../config.js')
const http = require('../../http.js')
const app = getApp()
var page = 1
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let titleH = (app.globalData.statusBarHeight * 750 / app.globalData.windowHeight) + 70;
    console.log()
    this.setData({
      titleH: titleH,
      userInfo: app.globalData.userInfo
    })
    this.getPersonalData()
    page = 1
    this.getPersonalList(page)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  back: function () {
    wx.navigateBack({
      delta: 1,
    })
  },

  bindscrolltolower: function () {
    console.log("bindscrolltolower")
    page ++
    this.getPersonalList(page)
  },

  getPersonalList: function (p) {
    var that = this
    http.request(
      config.personal,
      'POST', {
        page: p,
        pageSize: 20,
      },
      function (res) {
        if (res.data != null) {
          if (p == 1) {
            that.setData({
              personalList: res.data
            })
          } else {
            that.setData({
              personalList: that.data.personalList.concat(res.data)
            })
          }
        }
      },
      function (err) {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      }
    )
  },

  getPersonalData: function () {
    var that = this
    http.request(
      config.statistic,
      'GET', null,
      function (res) {
        if (res.data != null) {
          that.setData({
            personalData: res.data
          })
        }
      },
      function (err) {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      }
    )
  }
})